interface TreeItem {
    children: Array<TreeItem>
}

type Compare = ( item:TreeItem )=> boolean;

interface TreeUtils {
    treeFilter( dataList:Array<TreeItem>, compare ):Array<TreeItem>;
}

class TreeUtils {

    treeFilter( dataList:Array<TreeItem>=[], compare:Compare ){
        let list = [];
        for( let i=0; i<dataList.length; i++ ){
            let item:TreeItem = dataList[i];
            let res = compare( item );
            if( res ){
                list.push( item );
            }
            if( Array.isArray( item.children ) && item.children.length ){
               let subList = this.treeFilter( item.children, compare );
               item.children = subList;
            }
        }
        return list;
    }
}

export default new TreeUtils();